package com.platform.qujia.service.impl;

import com.platform.qujia.dao.AppUserInfoMapper;
import com.platform.qujia.pojo.AppUserInfo;
import com.platform.qujia.service.AppUserSyncService;
import com.platform.qujia.utils.StringUtils;
import com.platform.qujia.utils.yunHua.yunHuaPayUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class AppUserSyncServiceImpl implements AppUserSyncService {
    @Resource
    private AppUserInfoMapper appUserInfoMapper;

    @Override
    @Async
    public void syncUser(String mobilePhone) {
        log.info("到云化获取id，手机号【{}】，当前线程【{}】", mobilePhone,Thread.currentThread());
        String yunhuaUserId = yunHuaPayUtils.sendUser(mobilePhone);
        log.info("云化返回的id【{}】", yunhuaUserId);


        String res = yunHuaPayUtils.syncUser(mobilePhone, yunhuaUserId);
        log.info("同步云化返回的结果【{}】", res);

        AppUserInfo appUserInfo = new AppUserInfo();
        appUserInfo.setMobilePhone(mobilePhone);
        appUserInfo.setYunhuaUserId(yunhuaUserId);
        if(StringUtils.isNotEmpty(yunhuaUserId)){
            appUserInfoMapper.updateYunHuaUserIdByPhone(appUserInfo);
        }
    }

}
